package cn.uestc.labhms.modules.hms.util;

import cn.uestc.labhms.modules.hms.entity.Vo.ExcelVo;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.read.builder.ExcelReaderBuilder;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Mu.tz
 *
 */
public class ExcelUtil {
    /**
     * 获取excel中数据，封装到ExcelVo实体中
     * @param fileName
     * @param sheetNo
     * @return
     */
//    public ExcelVo noModelRead(String fileName, Integer sheetNo) {
//        // 这里 只要，然后读取第一个sheet 同步读取会自动finish
//        EasyExcel.read(fileName, new NoModelDataListener()).sheet(sheetNo).doRead();
//        return NoModelDataListener
//    }

    /**
     * 读取sheet名
     * @param fileName
     * @return
     */
    public static List<ReadSheet> readSheets(String fileName) {
        // 读取sheet名
        File file = new File(fileName);
        ExcelReaderBuilder excelReaderBuilder = EasyExcel.read(file);
        ExcelReader build = excelReaderBuilder.build();
        List<ReadSheet> readSheets = build.excelExecutor().sheetList();
        return readSheets;
    }
}
